package com.cloudkinto.enumType.common;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.enums.IEnum;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author long
 */
public enum CountryEnum implements IEnum<String> {
    /**
     *
     */
    US("USA", "美国", "USD"),
    CN("China", "中国", "RMB"),
    JP("Japan", "日本", "JPY"),
    CA("Canada", "加拿大", "CAD"),
    GB("Great Britain", "大不列颠", "CBP");


    private final String nameEn;
    private final String nameCn;
    private final String currency;

    CountryEnum(String nameEn, String nameCn, String currency) {
        this.nameEn = nameEn;
        this.nameCn = nameCn;
        this.currency = currency;
    }

    @Override
    public String getValue() {
        return name();
    }

    public String getCurrency() {
        return this.currency;
    }

    public static String getNameEnByCountryRegionCode(String countryRegionCode) {
        if (StrUtil.isEmpty(countryRegionCode)) {
            return null;
        }
        for (CountryEnum countryEnum : values()) {
            if (countryEnum.getValue().equals(countryRegionCode)) {
                return countryEnum.nameEn;
            }
        }
        return null;
    }

    public static List<Map<String, String>> getCountryEnumList() {
        List<Map<String, String>> list = new ArrayList<>();
        for (CountryEnum countryEnum : values()) {
            Map<String, String> map = new HashMap<>();
            map.put("nameEn", countryEnum.nameEn);
            map.put("nameCn", countryEnum.nameCn);
            map.put("currency", countryEnum.currency);
            map.put("countryRegionCode", countryEnum.getValue());
            list.add(map);
        }
        return list;
    }

    /**
     * 结算币种
     */
    public static List<String> getCurrencyList() {
        ArrayList<String> list = new ArrayList<>();
        for (CountryEnum countryEnum : values()) {
            list.add(countryEnum.currency);
        }
        return list;
    }

    /**
     * 国家二字码
     */
    public static List<String> getCountryList() {
        ArrayList<String> list = new ArrayList<>();
        for (CountryEnum countryEnum : values()) {
            list.add(countryEnum.getValue());
        }
        return list;
    }
}
